"""
Author: HuWen
@file: page_enterprise_info.py
@dateTime: 2025/7/7 10:20
加油加油！！！
"""
from locators.basicSecurityInformation.loc_enterprise_info import LocEnterpriseInfo

"""
Author: HuWen
@file: page_enterprise_info.py
@dateTime: 2025/7/2 13:59
加油加油！！！
企业档案信息编辑
"""
# page_enterprise_info.py
from playwright.sync_api import Page
from common.base_page import BasePage
from common.logger import logger


class EnterpriseInfoPage(BasePage):
    def __init__(self, page: Page):
        super().__init__(page)

    def edit_enterprise_info(self, park_code, enterprise_code, parent_enterprise_name, enterprise_name,
                             enterprise_abbreviation,region,register_address, production_address, legal_representative,
                             enterprise_leader, leader_phone, leader_telephone, postcode, enterprise_website,
                             credit_code, business_scope, chemical_park_name, factory_area, registered_capital,
                             enterprise_email, enterprise_fax):
        logger.info('开始编辑企业信息')
        self.click(LocEnterpriseInfo.loc_safety_management_menu)
        self.click(LocEnterpriseInfo.loc_edit_button)

        self.fill(LocEnterpriseInfo.loc_park_code, park_code)
        self.fill(LocEnterpriseInfo.loc_enterprise_code, enterprise_code)
        self.fill(LocEnterpriseInfo.loc_parent_enterprise_name, parent_enterprise_name)
        self.fill(LocEnterpriseInfo.loc_enterprise_name, enterprise_name)
        self.fill(LocEnterpriseInfo.loc_enterprise_abbreviation, enterprise_abbreviation)
        # self.page.wait_for_load_state("networkidle")
        # self.click(LocEnterpriseInfo.loc_region_select)

        self.select(LocEnterpriseInfo.loc_region_select,region)


        self.fill(LocEnterpriseInfo.loc_register_address, register_address)
        self.fill(LocEnterpriseInfo.loc_production_address, production_address)

        self.click(LocEnterpriseInfo.loc_coordinate_pick_button)
        self.page.locator("canvas").click(position={"x": 567, "y": 416})
        self.click(LocEnterpriseInfo.loc_confirm_button)
        self.click(LocEnterpriseInfo.loc_boundary_button)
        self.click(LocEnterpriseInfo.loc_boundary_sub)
        self.click(LocEnterpriseInfo.loc_confirm_button)

        self.fill(LocEnterpriseInfo.loc_legal_representative, legal_representative)
        self.fill(LocEnterpriseInfo.loc_enterprise_leader, enterprise_leader)
        self.fill(LocEnterpriseInfo.loc_leader_phone, leader_phone)
        self.fill(LocEnterpriseInfo.loc_leader_telephone, leader_telephone)
        self.fill(LocEnterpriseInfo.loc_postcode, postcode)

        self.click(LocEnterpriseInfo.loc_establish_date)
        self.page.get_by_text("1", exact=True).nth(1).click()

        self.fill(LocEnterpriseInfo.loc_enterprise_website, enterprise_website)

        self.click(LocEnterpriseInfo.loc_scale_select)
        self.select(LocEnterpriseInfo.loc_scale_select, '中')
        self.click(LocEnterpriseInfo.loc_industry_type_select)
        self.select(LocEnterpriseInfo.loc_industry_type_select, '煤矿类')
        self.click(LocEnterpriseInfo.loc_business_type_select)
        self.select(LocEnterpriseInfo.loc_business_type_select, '不带储存设施经营（门店经营）')

        self.click(LocEnterpriseInfo.loc_import_involve)
        self.page.get_by_label("涉及进口:").locator("label").filter(has_text="否").locator("span").nth(1).click()
        self.page.locator("label").filter(has_text="贸易经营性进口").locator("span").nth(1).click()

        self.click(LocEnterpriseInfo.loc_investment_type_select)
        self.select(LocEnterpriseInfo.loc_investment_type_select, '国外投资')
        self.click(LocEnterpriseInfo.loc_enterprise_nature_select)
        self.page.get_by_text("国外投资股份有限(公司)").click()

        self.page.get_by_label("企业基本信息").get_by_text("采矿业", exact=True).click()
        self.page.get_by_text("住宿和餐饮业").click()
        self.click(LocEnterpriseInfo.loc_industry_classification_select)
        self.select(LocEnterpriseInfo.loc_industry_classification_select, '住宿业')

        self.fill(LocEnterpriseInfo.loc_credit_code, credit_code)
        self.fill(LocEnterpriseInfo.loc_business_scope, business_scope)

        self.click(LocEnterpriseInfo.loc_level_select)
        self.select(LocEnterpriseInfo.loc_level_select, '二级')

        self.click(LocEnterpriseInfo.loc_chemical_park)
        self.page.get_by_label("是否在化工园区内:").locator("label").filter(has_text="否").locator("span").nth(1).click()
        self.page.get_by_label("是否在化工园区内:").locator("label").filter(has_text="是").locator("span").nth(1).click()
        self.fill(LocEnterpriseInfo.loc_chemical_park_name, chemical_park_name)

        self.click(LocEnterpriseInfo.loc_production_status_select)
        self.select(LocEnterpriseInfo.loc_production_status_select, '未投产')

        self.fill(LocEnterpriseInfo.loc_factory_area, factory_area)

        self.click(LocEnterpriseInfo.loc_production_date)
        self.page.get_by_role("gridcell", name="27").locator("span").click()

        self.fill(LocEnterpriseInfo.loc_registered_capital, registered_capital)
        self.fill(LocEnterpriseInfo.loc_enterprise_email, enterprise_email)
        self.fill(LocEnterpriseInfo.loc_enterprise_fax, enterprise_fax)

        self.click(LocEnterpriseInfo.loc_is_large_scale)
        self.page.get_by_label("是否规模以上:").locator("label").filter(has_text="是").locator("span").nth(1).click()
        self.click(LocEnterpriseInfo.loc_is_key_enterprise)
        self.page.get_by_label("是否为重点企业:").get_by_text("是").click()
        self.page.get_by_label("是否为重点企业:").locator("label").filter(has_text="是").locator("span").nth(1).click()

        self.click(LocEnterpriseInfo.loc_submit_button)